package com.example.parse_springboot.entity;

import cn.hutool.core.util.ObjectUtil;
import com.yomahub.liteflow.exception.NullParamException;

import java.util.concurrent.ConcurrentHashMap;

public class MyContext {
    private final ConcurrentHashMap<String, Object> dataMap = new ConcurrentHashMap();

    public MyContext() {
    }

    private <T> void putDataMap(String key, T t) {
        if (ObjectUtil.isNull(t)) {
            throw new NullParamException("data can't accept null param");
        } else {
            this.dataMap.put(key, t);
        }
    }

    public boolean hasData(String key) {
        return this.dataMap.containsKey(key);
    }

    public <T> T getData(String key) {
        return (T) this.dataMap.get(key);
    }

    public <T> void setData(String key, T t) {
        this.putDataMap(key, t);
    }

    public ConcurrentHashMap<String, Object> getDataMap() {
        return dataMap;
    }
}
